import request from '../../utils/request'
// pages/position/position.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: '',
    phone: '',
    companyName:'',
    type:'',
    number:'',
    benefit:'',
    position:'',
    ability:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    request.get('position/1').then(p=>{
      console.log(p)
      if(p.status>0){
        var data = p.data
        that.setData({
          name: data.name,
          phone: data.phone,
          companyName:data.company_name,
          type:data.type,
          number:data.number,
          benefit:data.reward,
          position:data.position,
          ability:data.ability
        })
      }
    })
  },
  getValue:function(e){
    var name= e.currentTarget.dataset.name 
    this.setData({
      [name]:e.detail.value
    })
  },
  bindTextAreaBlur:function(o){
    var name= o.currentTarget.dataset.name 
    this.setData({
      [name]:o.detail.value
    })
  },
  submitForm:function(){
   var that = this 
    var data = that.data 
    var params={
      name: data.name,
      phone: data.phone,
      company_name:data.companyName,
      type:data.type,
      number:data.number,
      reward:data.benefit,
      position:data.position,
      ability:data.ability
    }
    request.post('position',params).then(res=>{
     if(res.status==200){
       wx.showToast({
         title: '提交成功',
         icon:"success"
       })
       wx.navigateBack({
         delta: 1,
       })
     }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})